package com.aaa.controller;

import com.aaa.entity.Emp;
import com.aaa.service.impl.EmpServiceImpl;
import com.aaa.vo.EmpSearchForm;
import com.aaa.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年09月29日14:21
 */
@Controller
@RequestMapping("emp")
public class EmpController {
    @Autowired
    private EmpServiceImpl empService;
    @RequestMapping("list")
    @ResponseBody
    public Result list(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "5")int pageSize,
                       @RequestBody EmpSearchForm empSearchForm) {
        System.out.println("2wadwa"+empSearchForm);

        return empService.findAll(currentPage, pageSize,empSearchForm);
    }

    @RequestMapping("add")
    @ResponseBody
    public Result add(@RequestBody Emp record){
        int add = empService.add(record);
        Result result = new Result(200, "添加成功", add);
        return result;
    }

    @RequestMapping("delete")
    @ResponseBody
    public  Result delete(int id){
        int delete = empService.delete(id);
        Result result = new Result(200, "删除成功", delete);
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    public  Result update(@RequestBody Emp record){
        int update = empService.update(record);
        Result result = new Result(200, "修改成功", update);
        return result;
    }
}
